/**
 * 
 */
package kr.co.insoft.core.repository.configration.vender.impl;

import java.util.List;

import kr.co.insoft.core.mapper.configration.vender.VenderMapper;
import kr.co.insoft.core.model.configration.vender.VenderEntityModel;
import kr.co.insoft.core.model.configration.vender.VenderTypeEntityModel;
import kr.co.insoft.core.model.paging.PagingModel;
import kr.co.insoft.core.repository.configration.vender.VenderRepository;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.RepositoryException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * @author skpark
 * 
 */
@Repository
public class VenderRepositoryImpl implements VenderRepository {

	@Autowired
	VenderMapper venderMapper;

	@Override
	public List<VenderEntityModel> getLists(PagingModel pagingModel)
			throws RepositoryException {
		try {
			Assert.notNull(pagingModel);
			Assert.notNull(pagingModel.getCurrentPage());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return venderMapper.getLists(pagingModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public int getTotalCount(PagingModel pagingModel)
			throws RepositoryException {
		try {
			Assert.notNull(pagingModel);
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return venderMapper.getTotalCount(pagingModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public List<VenderEntityModel> getList(VenderEntityModel venderEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderEntityModel);
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return venderMapper.getList(venderEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public void createVender(VenderEntityModel venderEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderEntityModel);
			Assert.notNull(venderEntityModel.getVenderName());
			Assert.notNull(venderEntityModel.getTypeSeq());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			venderEntityModel.setVenderid(venderMapper.getUuid());
			venderMapper.createVender(venderEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public void addVenderType(VenderTypeEntityModel venderTypeEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderTypeEntityModel);
			Assert.notNull(venderTypeEntityModel.getTypeSeq());
			Assert.notNull(venderTypeEntityModel.getType());
			Assert.notNull(venderTypeEntityModel.getTypeName());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			venderMapper.addVenderType(venderTypeEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}

	}

	@Override
	public void deleteVenderType() throws RepositoryException {
		try {
			venderMapper.deleteVenderType();
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}

	}

	@Override
	public VenderEntityModel getVender(VenderEntityModel venderEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderEntityModel);
			Assert.notNull(venderEntityModel.getVenderid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return venderMapper.getVender(venderEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public int isExistsVenderName(VenderEntityModel venderEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderEntityModel);
			Assert.notNull(venderEntityModel.getVenderName());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return venderMapper.isExistsVenderName(venderEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public void editVender(VenderEntityModel venderEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderEntityModel);
			Assert.notNull(venderEntityModel.getVenderid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			venderMapper.editVender(venderEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public void removeVender(VenderEntityModel venderEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(venderEntityModel);
			Assert.notNull(venderEntityModel.getVenderid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			venderMapper.removeVender(venderEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
}
